import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import FanqieAdmin from '../views/FanqieAdmin.vue'
import Login from '../views/Login.vue'
import Register from '../views/Register.vue'
import BookDetail from '../views/BookDetail.vue'
import BookLibrary from '../views/BookLibrary.vue'
import Bookshelf from '../views/Bookshelf.vue'
import Rank from '../views/Rank.vue'
import SearchResults from '../views/SearchResults.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView,
    },
    {
      path: '/admin',
      name: 'fanqie-admin',
      component: FanqieAdmin,
    },
    {
      path: '/login',
      name: 'login',
      component: Login,
    },
    {
      path: '/register',
      name: 'register',
      component: Register,
    },
    {
      path: '/book/:id',
      name: 'book-detail',
      component: BookDetail,
      props: true
    },
    {
      path: '/library',
      name: 'book-library',
      component: BookLibrary
    },
    {
      path: '/bookshelf',
      name: 'bookshelf',
      component: Bookshelf
    },
    {
      path: '/rank',
      name: 'rank',
      component: Rank
    },
    {
      path: '/search',
      name: 'search-results',
      component: SearchResults,
      props: route => ({ query: route.query.q })
    }
  ],
})

export default router